package exceptions;

import app.Token;
import gui.MainFrameCompiler;

/**
 *
 * @author Julio
 */
public class LexicoException extends Exception{
    
    private int type;
    private int line;
    
    private String message;
    
    private Token current;
    
    public static final int 
            OPENED_COMMENTS_NOT_CLOSED = 0, 
            INVALID_TOKEN = 1;

    public LexicoException(Token current){
        this.type = INVALID_TOKEN;
        this.line = current.getLine();
        this.current = current;
    }
    
    public LexicoException(int type){
        this.type = type;
    }
    
    @Override
    public void printStackTrace(){
        switch(type){           
            case OPENED_COMMENTS_NOT_CLOSED:
                
                message = "[ERRO]Comentario aberto e nao fechado!";
                MainFrameCompiler.getInstance().addErrorMessage(message);
                System.err.println(message);
                
                break;
                
            case INVALID_TOKEN:
                
                message = "[ERRO]Erro na linha %d.\nCaractere \"%s\" invalido.";
                message = String.format(message, line, current.getSimbol());
                MainFrameCompiler.getInstance().addErrorMessage(message);
                System.err.println(message);            
                
                break;
        }
    }

}
